<?php
/**
 * [模型]账号
 * 
 * @version $Id: Account.php 286 2012-05-02 06:00:59Z linsir123 $
 */
class modelAccount 
{
	/**
	 * @var 数据模型
	 */
	public $dbProfile;
	
	/**
	 * @var 数据模型
	 */
	public $dbAccount;
	
	/**
	 * @var 会员ID
	 */
	public $uId = 0;
	
	/**
	 * @var 允许提现的最低余额
	 */
	public $minBalance = 30;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		$this->dbAccount = D::account();
		$this->dbProfile = D::profile();
	}
	
	/**
	 * 取得账户相关信息
	 * // 账户余额,账户状态,离提现金额
	 */
	public function getInfo()
	{
		$account = $this->dbAccount->getBy('uid', $this->uId);
		
		///
		$balance = round($account['balance'], 2);
		$dis = $this->minBalance > $balance ? round($this->minBalance-$balance, 2) : 0;
		return array(
			'balance' => $balance,
			'state' => $account['state'],
			'dis' => $dis
		);
	}
	
	/**
	 * 验证是否可以申请返现
	 */
	public function canApplyPay($money)
	{
		$account = $this->dbAccount->getBy('uid', $this->uId);
		if ($account['state'] == 1)
			return array(false, '请稍后进行操作，该账户已在申请提现中');
			
		///
		$alipay = $this->dbProfile->getBy('uid', $this->uId, 'alipay');
		if (empty($alipay)) 
			return array(false, '请先绑定支付宝账号');
			
		///
		if ($account['balance'] < $this->minBalance) 
			return array(false, '账户余额满￥30.00，才可进行提现操作');
			
		///
		if (empty($money) || $money > $account['balance']) 
			return array(false, '提现金额不能大于账户余额');
			
		///
		return array(true, $alipay);
	}
}
